{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>frequency</th>\n",
       "      <th>RAM</th>\n",
       "      <th>size</th>\n",
       "      <th>disk</th>\n",
       "      <th>SSD</th>\n",
       "      <th>GPU</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>18200</td>\n",
       "      <td>2.6</td>\n",
       "      <td>16</td>\n",
       "      <td>15.4</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4999</td>\n",
       "      <td>1.8</td>\n",
       "      <td>4</td>\n",
       "      <td>13.6</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3699</td>\n",
       "      <td>1.6</td>\n",
       "      <td>4</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1024</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9999</td>\n",
       "      <td>1.6</td>\n",
       "      <td>8</td>\n",
       "      <td>14.0</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8599</td>\n",
       "      <td>2.2</td>\n",
       "      <td>8</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1024</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>23000</td>\n",
       "      <td>2.2</td>\n",
       "      <td>32</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1024</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>4699</td>\n",
       "      <td>2.3</td>\n",
       "      <td>8</td>\n",
       "      <td>13.3</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2999</td>\n",
       "      <td>2.6</td>\n",
       "      <td>4</td>\n",
       "      <td>13.0</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price  frequency  RAM  size  disk  SSD  GPU\n",
       "0  18200        2.6   16  15.4   512  yes  yes\n",
       "1   4999        1.8    4  13.6   512  yes  yes\n",
       "2   3699        1.6    4  13.0  1024   no   no\n",
       "3   9999        1.6    8  14.0   256  yes   no\n",
       "4   8599        2.2    8  15.6  1024   no  yes\n",
       "5  23000        2.2   32  15.6  1024  yes  yes\n",
       "6   4699        2.3    8  13.3   256  yes   no\n",
       "7   2999        2.6    4  13.0   256  yes   no"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "df=pd.read_csv('笔记本集合.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 制定规则，返回质量评分\n",
    "def get_quality(p):\n",
    "    res=[]\n",
    "    if p['size']<14:\n",
    "        res.append(5)\n",
    "    elif p['size']>=14:\n",
    "        res.append(10)\n",
    "    if p['RAM']<8:\n",
    "        res.append(4)\n",
    "    elif p['RAM']>=8:\n",
    "        res.append(10)\n",
    "    if p['GPU']=='yes':\n",
    "        res.append(10)\n",
    "    elif p['GPU']=='no':\n",
    "        res.append(3)\n",
    "#     return res\n",
    "    return np.mean(res)\n",
    "\n",
    "# 制定规则，返回经济评分\n",
    "def get_economy(p):\n",
    "    res=[]\n",
    "    if p['price']<=8000:\n",
    "        res.append(10)\n",
    "    elif p['price']>8000:\n",
    "        res.append(6)\n",
    "    return np.mean(res)\n",
    "\n",
    "# 制定规则，返回效用值\n",
    "def get_utility(p):\n",
    "    return p['quality']*0.4+p['economy']*0.6\n",
    "\n",
    "df['quality']=df.apply(lambda x:get_quality(x),axis=1)\n",
    "df['economy']=df.apply(lambda x:get_economy(x),axis=1)\n",
    "df['utility']=df.apply(lambda x:get_utility(x),axis=1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>frequency</th>\n",
       "      <th>RAM</th>\n",
       "      <th>size</th>\n",
       "      <th>disk</th>\n",
       "      <th>SSD</th>\n",
       "      <th>GPU</th>\n",
       "      <th>quality</th>\n",
       "      <th>economy</th>\n",
       "      <th>utility</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>18200</td>\n",
       "      <td>2.6</td>\n",
       "      <td>16</td>\n",
       "      <td>15.4</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>6.0</td>\n",
       "      <td>7.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4999</td>\n",
       "      <td>1.8</td>\n",
       "      <td>4</td>\n",
       "      <td>13.6</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>6.333333</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.533333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3699</td>\n",
       "      <td>1.6</td>\n",
       "      <td>4</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1024</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>7.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9999</td>\n",
       "      <td>1.6</td>\n",
       "      <td>8</td>\n",
       "      <td>14.0</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>7.666667</td>\n",
       "      <td>6.0</td>\n",
       "      <td>6.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8599</td>\n",
       "      <td>2.2</td>\n",
       "      <td>8</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1024</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>6.0</td>\n",
       "      <td>7.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>23000</td>\n",
       "      <td>2.2</td>\n",
       "      <td>32</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1024</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>6.0</td>\n",
       "      <td>7.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>4699</td>\n",
       "      <td>2.3</td>\n",
       "      <td>8</td>\n",
       "      <td>13.3</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2999</td>\n",
       "      <td>2.6</td>\n",
       "      <td>4</td>\n",
       "      <td>13.0</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>7.600000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price  frequency  RAM  size  disk  SSD  GPU    quality  economy   utility\n",
       "0  18200        2.6   16  15.4   512  yes  yes  10.000000      6.0  7.600000\n",
       "1   4999        1.8    4  13.6   512  yes  yes   6.333333     10.0  8.533333\n",
       "2   3699        1.6    4  13.0  1024   no   no   4.000000     10.0  7.600000\n",
       "3   9999        1.6    8  14.0   256  yes   no   7.666667      6.0  6.666667\n",
       "4   8599        2.2    8  15.6  1024   no  yes  10.000000      6.0  7.600000\n",
       "5  23000        2.2   32  15.6  1024  yes  yes  10.000000      6.0  7.600000\n",
       "6   4699        2.3    8  13.3   256  yes   no   6.000000     10.0  8.400000\n",
       "7   2999        2.6    4  13.0   256  yes   no   4.000000     10.0  7.600000"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
